# 12.4 Usage of JSON Conversion in JFinal

The usage of JSON conversion in JFinal can be divided into two categories: one is to use the configured JSON conversion, and the other is to specify a particular implementation for JSON conversion.

# 1. Using Configured JSON Implementation for Conversion

The following code will use the JSON implementation configured as described in the previous sections:

// Use renderJson in the Controller for JSON conversion and rendering to the client
renderJson();
renderJson(key, object);
renderJson(new String[]{...});

// Use JsonKit utility class for JSON conversion
JsonKit.toJson(...);
JsonKit.parse(...);
1
2
3
4
5
6
7
8

# 2. Using a Specified JSON Implementation for Conversion

The following code will use a specified JSON implementation for conversion:

// Temporarily specify to use FastJson implementation
FastJson.getJson().toJson(...);
FastJson.getJson().parse(...);

// Pass the converted JSON string directly to the Controller.renderJson(..) method
renderJson(FastJson.getJson().toJson(...));
1
2
3
4
5
6

The above usage allows you to temporarily break away from the configured JSON implementation and use a specified JSON implementation instead. This is useful in situations where you might need different JSON conversion strategies for different parts of your application.

Last Updated: 9/22/2023, 7:48:43 AM